﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Warehouse.Entites;
using Warehouse.IServices;
using Warehouse.Services.Repository;
using WCS.Entities.Api;
using WCS.ViewModels;

namespace Juionwarehouse.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class StorageController : ControllerBase
    {
        private readonly IStorageServices _Services;
        private readonly Repository<Storage> storage;
        public StorageController(IStorageServices services, Repository<Storage> storage)
        {
            _Services = services;
            this.storage = storage;
        }
        //显示
        [HttpGet]
        public IActionResult Show(string? StorageNumber)
        {
            //var sty=_Services.StorageShow(StorageNumber);
            return Ok(_Services.StorageShow(StorageNumber));
        }
        //添加
        [HttpPost]
        public dynamic Add(Storage model)
        {
            _Services.StorageAdd(model);
            return ApiResultHelp.Success();
        }

        //删除
        [HttpDelete]
        public async Task<ApiResult> Delete(string[] StorageNumber)

        {
            bool b=await storage.DeleteByIdAsync(StorageNumber);
            return ApiResultHelp.Success(StorageNumber);
        }

        ////移库
        //[HttpPost]
        //public ApiResult Update(string storageNumber)
        //{
        //    _Services.StorageUpdate(storageNumber);
        //    return ApiResultHelp.Success();
        //}

        [HttpGet]
        public async Task<ApiResult> PutStorageMaterial()
        {
            try
            {
                var res = await _Services.PutStorage();
                return ApiResultHelp.Success(res);
            }
            catch (Exception ex)
            {
                throw new Exception($"error info: {ex.Message}");
            }
        }

        [HttpPost]
        public async Task<ApiResult> chu(OutStorageModel outStorage)
        {
            try
            {
                _Services.OutStorage(outStorage);
                return ApiResultHelp.Success("成功");
            }
            catch (Exception ex)
            {
                throw new Exception($"error info: {ex.Message}");
            }
        }

    }
}
